<template>
    <div class="wiper">
        <Filter title="拣配单" :items="filterItems" :model="condition" />
        <Table :rowKey="rowKey" :buttons="buttons" :columns="columns" :data="data" :pagination="condition" />
    </div>
</template>
<script>
import { message, Modal } from "ant-design-vue";
import Filter from "@/components/Filter";
import Table from "@/components/Table";
import { pager } from "@/api/order/picking";
import {
    ColumnProps, FilterItems, FilterCondition
} from "./config";
import { Dictionary } from "../../utils/Dictionary";

export default {
    name: 'picking',
    data() {
        return {
            filterItems: FilterItems,
            data: [{}],
            rowKey: 'pickId',
            columns: ColumnProps,
            condition: {
                    ...FilterCondition,
                    onChange: (page, pageSize)=>{
                        this.condition.current = page;
                        this.condition.pageSize = pageSize;
                        this.load();
                    }
                },
        }
    },
    components: {
        Filter,
        Table
    },
    computed: {
      isDictionary() {
          return this.$store.state.dictionary;
      },
    },
    watch: {
      isDictionary(data) {
          this._statusType(data);
      },
    },
    mounted() {
        this.load();
        this._statusType(this.$store.state.dictionary);
    },
    methods: {
        /**
         * 加载数据
         */
        load() {
            pager(this.condition).then(res => {
                this.data = res.data.rows;
                this.condition.total = res.data.total;
            })
        },

        _rename(list, key = "id"){
                return list?.map(item => {
                    return {label: item.name, value: item[key],children: this._rename(item.children)}
                });
            },
        /**
       * 状态
       * @param data
       * @private
       */
      _statusType(data) {
          const statusTypes = this._rename(data.filter(item => item.code === Dictionary.PICK_STATUS_TYPE)
             .map(item => item.children)[0], "code");
          this.filterItems.filter(item => item.key === 'status')[0].data = statusTypes;
          
      },

    }
}
</script>
<style>

</style>
